<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>COVID-19 Data Display</title>
    <!-- 引入 Element UI 的 CSS -->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <!-- 引入 Vue.js -->
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <!-- 引入 Axios -->
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <!-- 引入 Element UI 的 JS -->
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
</head>
<body>
    <div id="app">
          <h1>型冠状病毒数据实时展示</h1>
        <el-table :data="covidData" style="width: 100%">
            <el-table-column prop="updated" label="更新时间" :formatter="formatDate"  width="180"></el-table-column>
            <el-table-column prop="cases" label="确诊病例"></el-table-column>
            <el-table-column prop="todayCases" label="今日新增确诊"></el-table-column>
            <el-table-column prop="deaths" label="死亡病例"></el-table-column>
            <el-table-column prop="todayDeaths" label="今日新增死亡"></el-table-column>
            <el-table-column prop="recovered" label="康复病例"></el-table-column>
            <el-table-column prop="todayRecovered" label="今日新增康复"></el-table-column>
            <el-table-column prop="active" label="活跃病例"></el-table-column>
            <el-table-column prop="critical" label="重症病例"></el-table-column>
        </el-table>
    </div>

    <script>
        new Vue({
            el: '#app',
            data() {
                return {
                    covidData: []
                };
            },
          mounted() {
            this.fetchCovidData();
          },
            methods: {
                fetchCovidData() {
                    axios.get('https://disease.sh/v3/covid-19/all')
                  .then(response => {
                        this.covidData = [response.data];
                    })
                  .catch(error => {
                        this.$message.error('Failed to fetch COVID-19 data: ' + error.message);
                    });
                },
            formatDate(row, column, cellValue) {
                    const date = new Date(cellValue);
                    return date.toLocaleString();
                }
            }
        });
    </script>
</body>
</html>
